home *** CD-ROM | disk | FTP | other *** search
- /*
- * AZN_DBUG.C
- *
- * Utility 'C' functions for debugging apps
- * © Andrew Nemeth, Warrimoo Australia, 1995
- * aznemeng@zeta.org.au
- *
- * File Created: 6 Mar 95
- * File Ammended: 6, 7, 11, 12, 21 Mar;
- * 3 Jun;
- * 7, 23 Oct 95.
- */
-
-
- #include "AZN_DBUG.H" // debugging utilites
-
- #ifndef NDEBUG
-
-
- #include <new.h> // ANSI operator 'new' errors
- #include <stdio.h> // ANSI sprintf() & file functions
- #include <stdlib.h> // ANSI exit()
- #include <string.h> // ANSI memset()
- #include <time.h> // ANSI date & time
-
- #ifdef __MWERKS__
- // Mac Metrowerks SIOUX i/o
- #include <sioux.h>
- #endif
-
-
- // USEFUL DEFINES
- // use for low-level MAC debugger
- //#define MAC_LOW_LEVEL
-
-
-
- // FILE FUNCTIONS
- //
- static void noMoreMem ( void );
-
-
-
-
- void INIT_DEBUG ( void )
- //
- // set the function ptr for
- // global operator new failures
- //
- {
- set_new_handler( noMoreMem );
-
- #ifdef __SIOUX__
- // Set sioux display options
- SIOUXSettings.asktosaveonclose = FALSE;
- SIOUXSettings.columns = 40;
- SIOUXSettings.rows = 2;
- #endif
- }
-
-
-
- void noMoreMem ( void )
- //
- // Signal memory failure
- //
- {
- #ifdef MAC_LOW_LEVEL
- DebugStr( "\pAZN•Operator New failed!" );
- #else
- printf( "%s", "AZN•Operator New failed!" );
- exit( 0 );
- #endif
- }
-
-
-
- void myAlert ( char * txtFile, unsigned ushLine )
- //
- // Signal assertion failure
- //
- {
- #ifdef MAC_LOW_LEVEL
- char txtPrompt[256] = { "\0" };
-
- sprintf( txtPrompt, "~Assertion Failed: %s, line %u", txtFile, ushLine );
- // note the above is a trick! Use '~' as first char
- // as this is ASCII 126. When we come to typecase the
- // char to a 'StringPtr' below, it will fool DebugStr into
- // thinking that it has a pascal string 126 chars long!
- //
- DebugStr( (StringPtr)&txtPrompt[0] );
- #else
- printf( "Assertion Failed: %s, line %u", txtFile, ushLine );
- exit( 0 );
- #endif
- }
-
-
-
-
- void SALT_MEMORY ( void * vptrBuff, long lgSize )
- //
- // Salt deadly value into a block of memory.
- // Value used is '0xA3', which if de-referenced
- // by accident will play merry havoc (on Macs!)
- // See Steve Maguire "Writing Solid Code" p.49
- //
- {
- memset( vptrBuff, 0xA3, size_t(lgSize) );
- }
-
-
-
- void myDBG_FileString ( char * txtBlurb, char * txtSourceFile, unsigned ushLineNo )
- //
- // Dump the 'txtBlurb' into a debug file.
- // Also dumpts the source file & line number,
- // as well as a date stamp as to when write was done
- // Using ANSI, dump the current date/time
- // into the char * given
- //
- // Format: "Saturday, 21 Oct 1995 at 02:21:00 PM"
- //
- {
- #define ktxtFileName "AZN_DBUG.TXT"
-
- #define kshBuffSize 50
-
- FILE * ptrrecFILE;
- time_t ulgNow;
- struct tm * ptrrecDate;
- char txtMyDate[ kshBuffSize ],
- txtOutput[ 256 ];
- char * txtFormat = { "%A, %d %b %Y at %I:%M:%S %p" };
-
- // grab today's date/ time as ANSI struct
- ulgNow = time( NULL );
- ptrrecDate = localtime( &ulgNow );
- strftime( txtMyDate, kshBuffSize, txtFormat, ptrrecDate );
- // open debug file for writing
- ptrrecFILE = fopen( ktxtFileName, "a" );
- // output user's blurb
- fputc( '\n', ptrrecFILE );
- sprintf( txtOutput, "\"%s\"\nSource: %s\nLine: %u\nAt: %s\n", \
- txtBlurb, txtSourceFile, ushLineNo, txtMyDate );
-
- fputs( txtOutput, ptrrecFILE );
- // close debug file
- fclose( ptrrecFILE );
- }
-
- #endif
-